home *** CD-ROM | disk | FTP | other *** search
- // unzip.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "zdemo.h"
- #include "unzip.h"
- #include <zip.h>
- #include "czip.h"
- #include "mainfrm.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // CUnZip dialog box
-
-
- CUnZip::CUnZip(CWnd* pParent /*=NULL*/)
- : CDialog(CUnZip::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUnZip)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
- void CUnZip::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUnZip)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CUnZip, CDialog)
- //{{AFX_MSG_MAP(CUnZip)
- ON_BN_CLICKED(IDCOMMENT, OnComment)
- ON_EN_CHANGE(IDC_EDITFILENAME, OnChangeEditfilename)
- ON_BN_CLICKED(IDVIEW, OnView)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // CUnZip message handlers
-
-
-
-
- /////////////////////////////////////////////////////////////////////////////////
- // WM_INITDIALOG
- BOOL CUnZip::OnInitDialog()
- {
- CString CurrentPath;
-
- CDialog::OnInitDialog();
- if ( CurrentZipFile == "" ) // a zip file is compulsory
- {
- MessageBox( "Please select a zip file!", "Zip Studio", MB_OK | MB_ICONEXCLAMATION );
- PostMessage( WM_CLOSE );
- return TRUE;
- }
- // Also, this zip file must exist and be actually ZIP compatable!
- if ( !IsThisFileAZipFile( CurrentZipFile ))
- {
- MessageBox( "When you choose to unzip a file\nyou must specify a valid zip file before!", "Zip Studio", MB_OK | MB_ICONEXCLAMATION );
- PostMessage( WM_CLOSE );
- return TRUE;
- }
- // we just set the default values
- CheckDlgButton( IDC_CHECKPATH, 1 );
- CheckRadioButton( IDC_RADIOALWAYS, IDC_RADIOPROMPT, IDC_RADIOALWAYS );
- SetDlgItemText( IDC_EDITFILENAME, "*.*");
- SendDlgItemMessage( IDC_EDITFILENAME , EM_LIMITTEXT, 178 );
- // Activate or not the COMMENT button
- if ( GetZipCommentLength( CurrentZipFile) <2 )
- GetDlgItem( IDCOMMENT)->EnableWindow( FALSE );
- GetDlgItem( IDC_EDITFILENAME)->SetFocus( );
- GetDlgItem( IDC_EDITFILENAME)->SendMessage( EM_SETSEL, TRUE, MAKELONG( 0, -1L ));
- return FALSE; // return TRUE unless you set the focus to a control
- }
-
-
- /////////////////////////////////////////////////////////////////////////////////
- // WM_COMMAND ( IDOK )
- void CUnZip::OnOK()
- {
- // we simply call the unzip main function
- CString Mask, FileName;
- int Overwrite, KeepPath;
- GetDlgItemText( IDC_EDITFILENAME, FileName.GetBuffer( 180 ), 178);
- FileName.ReleaseBuffer();
- if ( FileName.GetLength() == 0 )
- {
- MessageBeep( 0 );
- return;
- }
- if ( IsDlgButtonChecked( IDC_RADIOPROMPT) )
- Overwrite = OVERWRITE_QUERY;
- else if ( IsDlgButtonChecked( IDC_RADIONEVER) )
- Overwrite = OVERWRITE_FALSE;
- else
- Overwrite = OVERWRITE_TRUE;
- KeepPath = IsDlgButtonChecked( IDC_CHECKPATH)?1:0;
- // set the values and Launch the zip process
- ((CMainFrame*)AfxGetMainWnd())->sMask = FileName;
- ((CMainFrame*)AfxGetMainWnd())->iOverwrite = Overwrite;
- ((CMainFrame*)AfxGetMainWnd())->bPath = KeepPath;
- ((CMainFrame*)AfxGetMainWnd())->PostMessage( PM_UNZIP );
- CDialog::OnOK();
- }
-
-
-
- /////////////////////////////////////////////////////////////////////////////////
- // WM_COMMAND ( IDCOMMENT )
- void CUnZip::OnComment()
- {
- UINT iBufferSize;
- CString TheComment;
-
- if ( ( iBufferSize = GetZipCommentLength( CurrentZipFile)) <2 )
- {
- GetDlgItem( IDCOMMENT)->EnableWindow( FALSE );
- return;
- }
- if ( iBufferSize > 32000 )
- {
- MessageBox( "Comment too long!\nWith this demo, comment longer than 32000 bytes\nwill not be displayed.","Zip Studio", MB_OK | MB_ICONEXCLAMATION );
- GetDlgItem( IDCOMMENT)->EnableWindow( FALSE );
- return;
- }
- GetZipComment( CurrentZipFile, TheComment.GetBuffer( iBufferSize ));
- TheComment.ReleaseBuffer();
- MessageBox( TheComment, CurrentZipFile );
- }
-
-
- /////////////////////////////////////////////////////////////////////////////////
- // WM_COMMAND ( EN_CHANGE, IDC_EDITFILENAME )
- void CUnZip::OnChangeEditfilename()
- {
- // Disable the OK button if no filename
- CString Temp;
- GetDlgItemText( IDC_EDITFILENAME, Temp.GetBuffer(160), 158 );
- Temp.ReleaseBuffer();
- if ( Temp.GetLength() == 0 )
- GetDlgItem( IDOK )->EnableWindow( FALSE );
- else
- GetDlgItem( IDOK )->EnableWindow( TRUE );
- }
-
-
-
- /////////////////////////////////////////////////////////////////////////////////
- // WM_COMMAND ( IDVIEW )
- void CUnZip::OnView()
- {
- // Send PM_VIEW to activate the View process from MainFrame...
- CString Mask, FileName;
- GetDlgItemText( IDC_EDITFILENAME, FileName.GetBuffer( 180 ), 178);
- FileName.ReleaseBuffer();
- if ( FileName.GetLength() == 0 )
- {
- MessageBeep( 0 );
- return;
- }
- // set the values and Launch the view process
- ((CMainFrame*)AfxGetMainWnd())->sMask = FileName;
- ((CMainFrame*)AfxGetMainWnd())->PostMessage( PM_VIEW );
- CDialog::OnOK();
- }
-